package com.hxd.otc.module.wallet.presenter;

import android.support.annotation.NonNull;

import com.hxd.otc.base.BaseBean;
import com.hxd.otc.module.wallet.bean.WalletFeeRuleBean;
import com.hxd.otc.module.wallet.contract.WalletAECQuickWithdrawContract;
import com.hxd.otc.module.wallet.model.WalletModel;
import com.hxd.otc.mvp.base.BasePresenter;
import com.hxd.otc.net.BaseObserver;

import java.util.ArrayList;

/**
 * 包  名 :  com.hxd.otc.module.wallet.presenter
 * 类  名 :  AECQuickWithdrawPresenter
 * 作  者 :  卫广玉
 * 时  间 :  2018/6/19 19:45
 * 描  述 :  ${TODO}
 */
public class AECQuickWithdrawPresenter extends BasePresenter<WalletAECQuickWithdrawContract.View> implements WalletAECQuickWithdrawContract.Presenter {

    private final WalletModel mModel;

    public AECQuickWithdrawPresenter(WalletAECQuickWithdrawContract.View view) {
        super(view);
        mModel = WalletModel.getInstance();
    }

    @Override
    public void start() {

    }

    /**
     * //获取验证码
     *
     * @param phoneHost
     * @param phoneNumber
     * @param type
     */
    @Override
    public void getSmsCode(String phoneHost, String phoneNumber, String type) {
        mView.setSMSEnable(false);
        mModel.getCode(new BaseObserver() {
            @Override
            public void onNext(String title, Object o) {
                mView.SmsSendSuccess();
            }

            @Override
            public void onError(int errType, String errMessage) {
                mView.showToast(errMessage);
                mView.setSMSEnable(true);
            }

        }, mView.<BaseBean>bindAutoDispose(), phoneHost, phoneNumber, type);
    }

    @Override
    public void bringCoinFeeRule() {
        mModel.bringCoinFeeRule(new BaseObserver<ArrayList<WalletFeeRuleBean>>() {
            @Override
            public void onNext(@NonNull String msg, @NonNull ArrayList<WalletFeeRuleBean> walletFeeRuleBeans) {
                mView.getbringCoinFeeRule(walletFeeRuleBeans);
                mView.onHideLoading();
            }

            @Override
            public void onError(int errType, @NonNull String errMessage) {
                mView.onHideLoading();
                mView.showToast(errMessage);
            }
        },mView.<BaseBean<ArrayList<WalletFeeRuleBean>>>bindAutoDispose());
    }

    /**
     * AEC转账
     *
     * @param amount      数量
     * @param captchCode  验证码 ,
     * @param coinType    币种
     * @param fromAddress 源钱包地址
     * @param fundPasswd  交易密码
     * @param orderId     (string, optional): 订单号:普通交易不需要填写，如果是商家扫描订单，需要添加 ,
     * @param payType     支付方式：0 AEC转账(AEC付款) 1 AEC商家支付 2 MSC商家支付 ,
     * @param toAddress   目标钱包地址
     */
    @Override
    public void coinTransfer(String amount, String captchCode, String coinType, String fromAddress, String fundPasswd, String orderId, String payType, String toAddress) {
        //转账不可重复点击
        mView.setTransferEnable(false);
        mView.onShowLoading();
        mModel.coinTransfer(new BaseObserver<BaseBean>() {
            @Override
            public void onNext(String title, BaseBean bean) {
                mView.onHideLoading();
                mView.transferSuccess();
                mView.setTransferEnable(true);
            }

            @Override
            public void onError(int errType, String errMessage) {
                mView.onHideLoading();
                mView.showToast(errMessage);
                mView.setTransferEnable(true);
            }
        }, mView.<BaseBean>bindAutoDispose(), amount, captchCode, coinType, fromAddress, fundPasswd, orderId, payType, toAddress);
    }

}
